package com.ht.medicaltreatment.viewmodel

import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.bean.HaoCaiDetailBean
import com.ht.medicaltreatment.bean.HaoCaiDetailData
import com.ht.medicaltreatment.bean.SuccessBean
import com.ht.medicaltreatment.http.api.HaoCaiDetailAPI
import com.ht.medicaltreatment.http.api.HaoCaiShenPiDetailAPI

class HaoCaiDetailViewModel : BaseViewModel(){
    fun getDetail(id:String,onResult:(HaoCaiDetailData)->Unit){
        EasyHttp.post(this)
            .api(HaoCaiDetailAPI(id))
            .request(object : OnHttpListener<HaoCaiDetailBean>{
                override fun onHttpSuccess(result: HaoCaiDetailBean) {
                    if(result.code == 200){
                        onResult(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message!!)
                }
            })
    }

    fun shenPi(id:String,remark:String,sign:String,onResult:(SuccessBean)->Unit){
        EasyHttp.post(this)
            .api(HaoCaiShenPiDetailAPI(id,remark,sign))
            .request(object : OnHttpListener<SuccessBean>{
                override fun onHttpSuccess(result: SuccessBean) {
                    if(result.code == 200){
                        onResult(result)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message!!)
                }
            })
    }
}
